//
//  BYHomeBannerView.m
//  OCDemo
//
//  Created by zhumuzhi on 2022/2/20.
//

#import "BYHomeBannerView.h"
#import "SDCycleScrollView.h"

@interface BYHomeBannerView ()<SDCycleScrollViewDelegate>

@property (nonatomic, strong) SDCycleScrollView  *cycleScrollView;

@end


@implementation BYHomeBannerView

#pragma mark - SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {
    
}

#pragma mark - CellHeight

+ (CGFloat)viewHeight {
    return kAutoWithSize(260);
}

#pragma mark - SetData

- (void)setImages:(NSMutableArray *)images {
    _images = images;
    NSMutableArray *imageGroups = [NSMutableArray array];
    for (NSString *imageName in images) {
        NSString *imgPath = [NSString stringWithFormat:@"%@.png", imageName];
        [imageGroups addObject:imgPath];
    }
    self.cycleScrollView.localizationImageNamesGroup = imageGroups;
}

#pragma mark - Init

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.cycleScrollView];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(kAutoWithSize(5));
        make.right.equalTo(self).offset(-kAutoWithSize(5));
        make.top.equalTo(self).offset(kAutoWithSize(5));
        make.bottom.equalTo(self).offset(-kAutoWithSize(5));
    }];
}

#pragma mark - LazyGet

- (SDCycleScrollView *)cycleScrollView {
    if (_cycleScrollView == nil) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero imageNamesGroup:nil];
        _cycleScrollView.delegate = self;
        _cycleScrollView.infiniteLoop = YES;
        _cycleScrollView.autoScroll = YES;
        _cycleScrollView.showPageControl = YES;
        _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        _cycleScrollView.currentPageDotColor = PUBLIC_ORANGE_COLOR;
        _cycleScrollView.placeholderImage = [UIImage imageNamed:@"placeholder_general"];
        _cycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        [_cycleScrollView setViewCornerRadius:kAutoWithSize(8)];
    }
    return _cycleScrollView;
}

@end
